package Offer.offer2016;

//������洢���������ʱprintln��ʾ�Զ����������print��ʾ�����������
//println()��ʾ����ո����ַ�ģ�ⲻ�󷽱㣬�����ַ��������ֶ���ת����ʧ���ݡ�

public class Test12 
{

	public static void main(String[] args) 
	{
	//	print1ToN(4);
		print1ToMaxnNum.print1ToMax(4);
	}
    public static void print1ToN(int n)
    {
    	if(n<=0)
    		return;
    	int[] number =new int[n];
    	for(int i=0;i<=n-1;i++)
    	{
    		number[i]=0;
    	}
    	while(add(number,n))
    	{
    		print(number,n);
    	}
    }
    public static boolean add(int[] number,int n)
    {
    	int takeover=0;
    	for(int i=n-1;i>=0;i--)
        {
    		int sum=number[i]+takeover;
    		if(i==n-1)
    		{
    			sum++;
    		}
    		
    		if(sum>=10)
    		{
    			if(i==0)
    			{
    				return false;
    			}
    			else
    			{
    				sum -= 10;
    				takeover=1;
    				number[i]= sum;
    			}
    		}
    		else
    		{
    			number[i]= sum;
    			break;
    		}
        }
    	return true;
    	
    }
    public static void print(int[] number,int n)
    {
    	boolean bool=false;
    	for(int i=0;i<=n-1;i++)
    	{
    		if(!bool&&number[i]!=0)
    		{
    			bool = true;
    		}
    		if(bool)
    		{
    			System.out.print(number[i]);
    		}
    	}
    	System.out.println();
    }
}


class print1ToMaxnNum{
	static void print1ToMax(int n){
		if(n <= 0){
			return ;
		}
		int []numArr = new int[n];
		print1ToMax(numArr,0);
	}
    static void print1ToMax(int []numArr, int index){
    	if(index == numArr.length){
    		printNumber(numArr);
    	}else{
    		for(int i = 0; i < 10; i++){
    			numArr[index] = i;
    			print1ToMax(numArr,index + 1);
    		}
    	}
    }
    static void printNumber(int []numArr){
    	int printNum = 0 ;
    	for(int i = 0,len = numArr.length; i < len; i ++){
    		printNum = printNum * 10 + numArr[i];
    	}
    	System.out.println(printNum);
    }
}
